]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
keyboard: Replace Keypad object with a "digits" JSON OSK keymap
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 26 Jan 2024 17:04:18 +0000 (18:04 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 29 Feb 2024 15:34:21 +0000 (16:34 +0100)
Drop some code, in favor of a numeric keypad that is driven through
the same JSON-based maps. This is also a first use of the "height"
key property in the JSON files, for the Enter key.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3162>

data/gnome-shell-osk-layouts.gresource.xml
data/osk-layouts/digits.json [new file with mode: 0644]
js/ui/keyboard.js

index b5112919c77110a3f8455ae27d350e109565c4a6..efaf47491bdff3d908effb4b5645b324f0400784 100644 (file)
@@ -12,6 +12,7 @@
     <file>ch+fr.json</file>
     <file>cz.json</file>
     <file>de.json</file>
+    <file>digits.json</file>
     <file>dk.json</file>
     <file>ee.json</file>
     <file>epo.json</file>
diff --git a/data/osk-layouts/digits.json b/data/osk-layouts/digits.json
new file mode 100644 (file)
index 0000000..83ac432
--- /dev/null
@@ -0,0 +1,83 @@
+{
+  "levels": [
+    {
+      "level": "",
+      "mode": "default",
+      "rows": [
+        [
+          {
+            "strings": [
+              "7"
+            ]
+          },
+          {
+            "strings": [
+              "8"
+            ]
+          },
+          {
+            "strings": [
+              "9"
+            ]
+          },
+          {
+            "action": "delete",
+            "iconName": "edit-clear-symbolic"
+          }
+        ],
+        [
+          {
+            "strings": [
+              "4"
+            ]
+          },
+          {
+            "strings": [
+              "5"
+            ]
+          },
+          {
+            "strings": [
+              "6"
+            ]
+          },
+          {
+            "iconName": "keyboard-enter-symbolic",
+            "keyval": "0xff0d",
+            "height": 2
+          }
+        ],
+        [
+          {
+            "strings": [
+              "1"
+            ]
+          },
+          {
+            "strings": [
+              "2"
+            ]
+          },
+          {
+            "strings": [
+              "3"
+            ]
+          }
+        ],
+        [
+          {
+            "width": 3,
+            "strings": [
+              "0"
+            ]
+          },
+          {
+            "action": "hide",
+            "iconName": "keyboard-hide-symbolic"
+          }
+        ]
+      ]
+    }
+  ],
+  "name": "Digits"
+}
index a3629f78d4afff6b8c2f2ba6e75b2a7fbcc29b1f..8f460bb52e4a0d8e5d41bac00f77548d9f69963a 100644 (file)
@@ -1084,63 +1084,6 @@ const EmojiSelection = GObject.registerClass({
     }
 });
 
-const Keypad = GObject.registerClass({
-    Signals: {
-        'keyval': {param_types: [GObject.TYPE_UINT]},
-    },
-}, class Keypad extends AspectContainer {
-    _init() {
-        let keys = [
-            {label: '1', keyval: Clutter.KEY_1, left: 0, top: 0},
-            {label: '2', keyval: Clutter.KEY_2, left: 1, top: 0},
-            {label: '3', keyval: Clutter.KEY_3, left: 2, top: 0},
-            {label: '4', keyval: Clutter.KEY_4, left: 0, top: 1},
-            {label: '5', keyval: Clutter.KEY_5, left: 1, top: 1},
-            {label: '6', keyval: Clutter.KEY_6, left: 2, top: 1},
-            {label: '7', keyval: Clutter.KEY_7, left: 0, top: 2},
-            {label: '8', keyval: Clutter.KEY_8, left: 1, top: 2},
-            {label: '9', keyval: Clutter.KEY_9, left: 2, top: 2},
-            {label: '0', keyval: Clutter.KEY_0, left: 1, top: 3},
-            {keyval: Clutter.KEY_BackSpace, icon: 'edit-clear-symbolic', left: 3, top: 0},
-            {keyval: Clutter.KEY_Return, extraClassName: 'enter-key', icon: 'keyboard-enter-symbolic', left: 3, top: 1, height: 2},
-        ];
-
-        super._init({
-            layout_manager: new Clutter.BinLayout(),
-            x_expand: true,
-            y_expand: true,
-        });
-
-        const gridLayout = new Clutter.GridLayout({
-            orientation: Clutter.Orientation.HORIZONTAL,
-            column_homogeneous: true,
-            row_homogeneous: true,
-        });
-        this._box = new St.Widget({layout_manager: gridLayout, x_expand: true, y_expand: true});
-        this.add_child(this._box);
-
-        for (let i = 0; i < keys.length; i++) {
-            let cur = keys[i];
-            let key = new Key({
-                label: cur.label,
-                iconName: cur.icon,
-            });
-
-            if (keys[i].extraClassName)
-                key.keyButton.add_style_class_name(cur.extraClassName);
-
-            let w, h;
-            w = cur.width || 1;
-            h = cur.height || 1;
-            gridLayout.attach(key, cur.left, cur.top, w, h);
-
-            key.connect('released', () => {
-                this.emit('keyval', cur.keyval);
-            });
-        }
-    }
-});
-
 export class KeyboardManager extends Signals.EventEmitter {
     constructor() {
         super();
@@ -1390,15 +1333,6 @@ export const Keyboard = GObject.registerClass({
         this._emojiSelection.hide();
         this._aspectContainer.add_child(this._emojiSelection);
 
-        this._keypad = new Keypad();
-        this._keypad.connectObject('keyval', (_keypad, keyval) => {
-            this._keyboardController.keyvalPress(keyval);
-            this._keyboardController.keyvalRelease(keyval);
-        }, this);
-        this._aspectContainer.add_child(this._keypad);
-        this._keypad.hide();
-        this._keypadVisible = false;
-
         this._updateKeys();
 
         this._keyboardController.connectObject(
@@ -1460,7 +1394,7 @@ export const Keyboard = GObject.registerClass({
         if (purpose === Clutter.InputContentPurpose.DIGITS ||
             purpose === Clutter.InputContentPurpose.NUMBER ||
             purpose === Clutter.InputContentPurpose.PHONE) {
-            this._onKeypadVisible(null, true);
+            keyboardModel = new KeyboardModel('digits');
         } else {
             let groups = [groupName];
             if (groupName.includes('+'))
@@ -1480,8 +1414,6 @@ export const Keyboard = GObject.registerClass({
 
             if (!keyboardModel)
                 return;
-
-            this._onKeypadVisible(null, false);
         }
 
         let levels = keyboardModel.getLevels();
@@ -1753,7 +1685,7 @@ export const Keyboard = GObject.registerClass({
 
     _updateCurrentPageVisible() {
         if (this._currentPage)
-            this._currentPage.visible = !this._emojiActive && !this._keypadVisible;
+            this._currentPage.visible = !this._emojiActive;
     }
 
     _setEmojiActive(active) {
@@ -1825,15 +1757,6 @@ export const Keyboard = GObject.registerClass({
         this._onGroupChanged();
     }
 
-    _onKeypadVisible(controller, visible) {
-        if (visible === this._keypadVisible)
-            return;
-
-        this._keypadVisible = visible;
-        this._keypad.visible = this._keypadVisible;
-        this._updateCurrentPageVisible();
-    }
-
     _onEmojiKeyVisible(controller, visible) {
         if (visible === this._emojiKeyVisible)
             return;